package com.peoit.honeycomb.dto;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

import com.peoit.honeycomb.domain.Accessory;
import com.peoit.honeycomb.domain.HoneycombProject;

/**
 * Created by Bing.Zeng on 2015/9/26.
 */
public class ProjectDto extends BaseDto {

	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

	private String userId;
	private String projectName; /// 项目名称
	private String projectCity; // 项目所在城市
	private String address; // 详细地址
	private String industryType; // 行业类型
	private String projectIntro; // 项目介绍
	private String moneyUse; // 资金用途
	private double totalStockMoney;// 股权总额
	private double sellStockMoney; // 发行总额
	private double perSellStockMoney;// 单股售卖金额
	private double successCondition;// 项目启动条件(投资百分比%)
	private double lowestSellingPercentage;// 起售股份所占比例
	private String endDate;// 结束时间
	private String dividendType; // 分红模式
	private double dividendPercent;// 分红比例
	private String stockholderPrivilege;// 股东特权说明
	private double investorEarnestPercent; // 投资者保证金比例
	private double projectEarnestPercent;// 项目保证金比例
	private String stockType; // 股权类型
	private String status; // 项目状态
	private String cancelRemarks;// 取消原因

	// 当前已投资金额
	private double investedAmount;
	// 用于页面显示，表示指定用户在该项目的投资额
	private double userInvestedAmount;
	// 该用户在该项目最近的一次投资时间 ，因为可能一个用户可以对某个项目投资多次
	private String userInvestedDate;
	private String marketAnalysis; // 市场分析
	private String sourceOfIncome; // 收入来源
	private String profitForecast; // 盈利预测
	private String teamIntroducation; // 团队介绍
	private Long investUserAmount; // 已投人数
	private String publisherName;// 项目发布人
	private String projectType; // 项目类别 动产/不动产

	// 各种图片
	private List<String> projectPhotos = new ArrayList<>(); // 项目图片
	private List<String> businessLicenses = new ArrayList<>(); // 营业执照
	private List<String> personCredits = new ArrayList<>(); // 个人信用报告
	private List<String> industryLicense = new ArrayList<>(); // 行业许可证

	// ===============================================assembler====================
	public static HoneycombProject toProject(ProjectDto dto) {
		HoneycombProject project = new HoneycombProject();
		project.setProjectName(dto.getProjectName());
		project.setProjectCity(dto.getProjectCity());
		project.setAddress(dto.getAddress());
		project.setProjectIntro(dto.getProjectIntro());
		project.setIndustryType(dto.getIndustryType());
		project.setStockType(dto.getStockType());
		project.setMoneyUse(dto.getMoneyUse());
		project.setTotalStockMoney(dto.getTotalStockMoney());
		project.setLowestSellingPercentage(dto.getLowestSellingPercentage());
		project.setSellStockMoney(dto.getSellStockMoney());
		project.setPerSellStockMoney(dto.getPerSellStockMoney());
		project.setSuccessCondition(dto.getSuccessCondition());
		project.setEndDate(strToDate(dto.getEndDate()));
		project.setDividendType(dto.getDividendType());
		project.setDividendPercent(dto.getDividendPercent());
		project.setInvestorEarnestPercent(dto.getInvestorEarnestPercent());
		project.setStockholderPrivilege(dto.getStockholderPrivilege());
		project.setStatus(dto.getStatus());
		project.setMarketAnalysis(dto.getMarketAnalysis());
		project.setSourceOfIncome(dto.getSourceOfIncome());
		project.setProfitForecast(dto.getProfitForecast());
		project.setTeamIntroducation(dto.getTeamIntroducation());
		project.setProjectType(dto.getProjectType());
		project.setProjectEarnestPercent(dto.getProjectEarnestPercent());
		return project;
	}

	public static ProjectDto toDto(HoneycombProject project) {
		ProjectDto dto = new ProjectDto();
		dto.setId(project.getId());
		dto.setProjectName(project.getProjectName());
		dto.setProjectCity(project.getProjectCity());
		dto.setAddress(project.getAddress());
		dto.setProjectIntro(project.getProjectIntro());
		dto.setIndustryType(project.getIndustryType());
		dto.setStockType(project.getStockType());
		dto.setMoneyUse(project.getMoneyUse());
		dto.setTotalStockMoney(project.getTotalStockMoney());
		dto.setLowestSellingPercentage(project.getLowestSellingPercentage());
		dto.setSellStockMoney(project.getSellStockMoney());
		dto.setPerSellStockMoney(project.getPerSellStockMoney());
		dto.setSuccessCondition(project.getSuccessCondition());
		dto.setEndDate(dateToStr(project.getEndDate()));
		dto.setDividendType(project.getDividendType());
		dto.setDividendPercent(project.getDividendPercent());
		dto.setInvestorEarnestPercent(project.getInvestorEarnestPercent());
		dto.setStockholderPrivilege(project.getStockholderPrivilege());
		dto.setStatus(project.getStatus());
		dto.setTeamIntroducation(project.getTeamIntroducation());
		dto.setProfitForecast(project.getProfitForecast());
		dto.setSourceOfIncome(project.getSourceOfIncome());
		dto.setMarketAnalysis(project.getMarketAnalysis());
		dto.setInvestUserAmount(project.getInvestedUserAmount());
		dto.setProjectType(project.getProjectType());
		// 计算当前已投资金额
		dto.setInvestedAmount(project.getSellStockMoney() - project.getAvailableAmount());
		// 获取项目的发布者
		dto.setPublisherName(project.getPublisher().getUserName());
		dto.setUserId(project.getPublisher().getId());
		dto.setProjectEarnestPercent(project.getProjectEarnestPercent());
		dto.setCancelRemarks(project.getCancelRemarks());
		// populate 各种图片
		Set<Accessory> accessories = project.getAccessories();
		for (Accessory accessory : accessories) {
			String type = accessory.getType();
			if (Config.PROJECT_PICTURE.equals(type)) {

				dto.projectPhotos.add(accessory.getFilePath());
			} else if (Config.BUSINESS_LICENSE.equals(type)) {
				dto.businessLicenses.add(accessory.getFilePath());
			} else if (Config.BUSINESS_PERMISSION.equals(type)) {
				dto.industryLicense.add(accessory.getFilePath());
			} else if (Config.PERSONAL_CREDIT_REPORT.equals(type)) {
				dto.personCredits.add(accessory.getFilePath());
			}
		}
		return dto;
	}

	////////////////////////////// getter&setters////////////////////

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getProjectName() {
		return projectName;
	}

	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}

	public String getProjectCity() {
		return projectCity;
	}

	public void setProjectCity(String projectCity) {
		this.projectCity = projectCity;
	}

	public String getIndustryType() {
		return industryType;
	}

	public void setIndustryType(String industryType) {
		this.industryType = industryType;
	}

	public String getProjectIntro() {
		return projectIntro;
	}

	public void setProjectIntro(String projectIntro) {
		this.projectIntro = projectIntro;
	}

	public String getMoneyUse() {
		return moneyUse;
	}

	public void setMoneyUse(String moneyUse) {
		this.moneyUse = moneyUse;
	}

	public double getTotalStockMoney() {
		return totalStockMoney;
	}

	public void setTotalStockMoney(double totalStockMoney) {
		this.totalStockMoney = totalStockMoney;
	}

	public double getSellStockMoney() {
		return sellStockMoney;
	}

	public void setSellStockMoney(double sellStockMoney) {
		this.sellStockMoney = sellStockMoney;
	}

	public double getPerSellStockMoney() {
		return perSellStockMoney;
	}

	public void setPerSellStockMoney(double perSellStockMoney) {
		this.perSellStockMoney = perSellStockMoney;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public String getDividendType() {
		return dividendType;
	}

	public void setDividendType(String dividendType) {
		this.dividendType = dividendType;
	}

	public double getSuccessCondition() {
		return successCondition;
	}

	public void setSuccessCondition(double successCondition) {
		this.successCondition = successCondition;
	}

	public double getInvestorEarnestPercent() {
		return investorEarnestPercent;
	}

	public void setInvestorEarnestPercent(double investorEarnestPercent) {
		this.investorEarnestPercent = investorEarnestPercent;
	}

	public double getDividendPercent() {
		return dividendPercent;
	}

	public void setDividendPercent(double dividendPercent) {
		this.dividendPercent = dividendPercent;
	}

	public String getStockholderPrivilege() {
		return stockholderPrivilege;
	}

	public void setStockholderPrivilege(String stockholderPrivilege) {
		this.stockholderPrivilege = stockholderPrivilege;
	}

	public double getUserInvestedAmount() {
		return userInvestedAmount;
	}

	public void setUserInvestedAmount(double userInvestedAmount) {
		this.userInvestedAmount = userInvestedAmount;
	}

	public String getUserInvestedDate() {
		return userInvestedDate;
	}

	public void setUserInvestedDate(String userInvestedDate) {
		this.userInvestedDate = userInvestedDate;
	}

	public List<String> getProjectPhotos() {
		return projectPhotos;
	}

	public void setProjectPhotos(List<String> projectPhotos) {
		this.projectPhotos = projectPhotos;
	}

	public List<String> getBusinessLicenses() {
		return businessLicenses;
	}

	public void setBusinessLicenses(List<String> businessLicenses) {
		this.businessLicenses = businessLicenses;
	}

	public List<String> getPersonCredits() {
		return personCredits;
	}

	public void setPersonCredits(List<String> personCredits) {
		this.personCredits = personCredits;
	}

	public List<String> getIndustryLicense() {
		return industryLicense;
	}

	public void setIndustryLicense(List<String> industryLicense) {
		this.industryLicense = industryLicense;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public static SimpleDateFormat getSdf() {
		return sdf;
	}

	public static void setSdf(SimpleDateFormat sdf) {
		ProjectDto.sdf = sdf;
	}

	private static Date strToDate(String str) {
		try {
			return sdf.parse(str);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return null;
	}

	private static String dateToStr(Date date) {
		try {
			return sdf.format(date);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return "";
	}

	public String getStockType() {
		return stockType;
	}

	public void setStockType(String stockType) {
		this.stockType = stockType;
	}

	public double getLowestSellingPercentage() {
		return lowestSellingPercentage;
	}

	public void setLowestSellingPercentage(double lowestSellingPercentage) {
		this.lowestSellingPercentage = lowestSellingPercentage;
	}

	public double getInvestedAmount() {
		return investedAmount;
	}

	public void setInvestedAmount(double investedAmount) {
		this.investedAmount = investedAmount;
	}

	public String getMarketAnalysis() {
		return marketAnalysis;
	}

	public void setMarketAnalysis(String marketAnalysis) {
		this.marketAnalysis = marketAnalysis;
	}

	public String getProfitForecast() {
		return profitForecast;
	}

	public void setProfitForecast(String profitForecast) {
		this.profitForecast = profitForecast;
	}

	public Long getInvestUserAmount() {
		return investUserAmount;
	}

	public void setInvestUserAmount(Long investUserAmount) {
		this.investUserAmount = investUserAmount;
	}

	public String getSourceOfIncome() {
		return sourceOfIncome;
	}

	public void setSourceOfIncome(String sourceOfIncome) {
		this.sourceOfIncome = sourceOfIncome;
	}

	public String getTeamIntroducation() {
		return teamIntroducation;
	}

	public void setTeamIntroducation(String teamIntroducation) {
		this.teamIntroducation = teamIntroducation;
	}

	public String getPublisherName() {
		return publisherName;
	}

	public String getProjectType() {
		return projectType;
	}

	public void setProjectType(String projectType) {
		this.projectType = projectType;
	}

	public void setPublisherName(String publisherName) {
		this.publisherName = publisherName;
	}

	public double getProjectEarnestPercent() {
		return projectEarnestPercent;
	}

	public void setProjectEarnestPercent(double projectEarnestPercent) {
		this.projectEarnestPercent = projectEarnestPercent;
	}

	public String getCancelRemarks() {
		return cancelRemarks;
	}

	public void setCancelRemarks(String cancelRemarks) {
		this.cancelRemarks = cancelRemarks;
	}

}
